﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Common;
using Common.Views;

namespace BL_WServices
{
    /// <summary>
    /// This is the Implementation of FaultsService which is bound by a ServiceContract
    /// </summary>
    [ServiceContract]
    public interface IFaultsService
    {
        /// <summary>
        /// Returns the Fault Status of an Order
        /// </summary>
        /// <param name="orderID">Of type guid. Used to get the fault status of a particular product depending on the order</param>
        /// <param name="productID">Of type int. Used to get the fault status of a particular product</param>
        /// <returns>Returns string</returns>
        [OperationContract]
        string GetFaultsForOrder(Guid orderID, int productID);

        /// <summary>
        /// Returns a list of detailed filter transactions depending on the productID and date
        /// </summary>
        /// <param name="startDate">Of type Date. Used to get the order between the startDate</param>
        /// <param name="endDate">Of type Date. Used to get the order between the endDate</param>
        /// <param name="productID">Of type int. Used to get the productID</param>
        /// <param name="username">Of type string. Used to get the order depending on the username</param>
        /// <returns>Returns a list of detailed filter transactions depending on the productID, and the purchase dates</returns>
        [OperationContract]
        IQueryable<OrdersView> FilterTransactions(DateTime startDate, DateTime endDate, int productID, string username);

        /// <summary>
        /// Gets a list of the fault categories
        /// </summary>
        /// <returns>Returns a list of the fault categories</returns>
        [OperationContract]
        IQueryable<FaultCategory> GetFaultCategories();

        /// <summary>
        /// User adds fault to the database and also categorizes that fault.
        /// An email is sent to the user containing a generated PDF and barcode image.
        /// The PDF contains the Date the item was reported, the fault id, the faulty product id, and the fault details
        /// </summary>
        /// <param name="faultID">Of type guid. Used to create a new faultID</param>
        /// <param name="faultCatID">Of type int. Used to get the fault categoryID of the fault</param>
        /// <param name="orderID">Of type guid. Used to get the orderID</param>
        /// <param name="productID">Of type int. Used to get the productID</param>
        /// <param name="details">Of type string. Used so that the user enters the fault details of the product</param>
        /// <param name="barcode">Of type byte. Used to create the barcode</param>
        /// <param name="username">Of type username. Used to enter get the user's email address</param>
        [OperationContract]
        void AddFault(Guid faultID, int faultCatID, Guid orderID, int productID, string details, byte[] barcode, string username);

        /// <summary>
        /// Gets a list of the faults
        /// </summary>
        /// <returns>Returns a list of the faults</returns>
        [OperationContract]
        IQueryable<Fault> GetAllFaults();

        /// <summary>
        /// Returns a list of fault details/log entries in descending order
        /// </summary>
        /// <returns>Returns a list of fault details/log entries in descending order, ordered by the date</returns>
        [OperationContract]
        IEnumerable<FaultView> SearchByDateDESC();

        /// <summary>
        /// Returns a list of faults depending on the startDate and endDate
        /// </summary>
        /// <param name="startDate">Of type DateTime. Used to get the earliest date</param>
        /// <param name="endDate">Of type DateTime. Used to get the latest date</param>
        /// <returns>Returns a list of faults depending on the startDate and endDate</returns>
        [OperationContract]
        IQueryable<FaultView> SearchByLogDate(DateTime startDate, DateTime endDate);

        /// <summary>
        /// Returns a list of faults depending on the faultID
        /// </summary>
        /// <param name="faultID">Of type Guid. Used to get the faultID</param>
        /// <returns>Returns a list of faults depending on the faultID</returns>
        [OperationContract]
        IQueryable<FaultView> SearchByFaultID(Guid faultID);

        /// <summary>
        /// Returns a list of faults depending on the username
        /// </summary>
        /// <param name="username">Of type string. Used to get the username</param>
        /// <returns>Returns a list of faults depending on the username</returns>
        [OperationContract]
        IQueryable<FaultView> SearchByClientID(string username);

        /// <summary>
        /// Returns the LogEntries by faultID, username, startDate and endDate
        /// </summary>
        /// <param name="faultID">Of type Guid. Used to get the faultID</param>
        /// <param name="username">Of type string. Used to get the username</param>
        /// <param name="startDate">Of type DateTime. Used to get the earliest date</param>
        /// <param name="endDate">Returns a list of faults depending on the startDate and endDate</param>
        /// <returns>Returns the LogEntries by faultID, username, startDate and endDate</returns>
        [OperationContract]
        IQueryable<FaultView> SearchByLogEntries(Guid faultID, string username, DateTime startDate, DateTime endDate);

        /// <summary>
        /// Get all the Log Entries for the Faults
        /// </summary>
        /// <returns>Returns all the log entries for the faults</returns>
        [OperationContract]
        IQueryable<FaultView> GetAllLogEntires();

        /// <summary>
        /// Gets a list of fault statuses
        /// </summary>
        /// <returns>Returns a list of fault statuses</returns>
        [OperationContract]
        IQueryable<FaultStatu> GetAllFaultStatuses();

        /// <summary>
        /// Used to add a new fault to the database and fault is categorized
        /// </summary>
        /// <param name="OrderID">Of type guid. Used to get the OrderID</param>
        /// <param name="faultID">Of type guid. Used to insert the faultID of the fault status being updated</param>
        /// <param name="details">Of type string. Used to enter the fault details of the reported product</param>
        /// <param name="statusID">Of type int. Used to add the statusID</param>
        [OperationContract]
        void UpdateFault(Guid OrderID, Guid faultID, string details, int statusID);
    }
}
